define(['moment','jquery', 'bootstrap', 'backend',"highcharts",'echarts','table','form','jquery-ui', 'jQDateRangeSlider','bootstrap-datetimepicker'], function (moment,$, undefined, Backend,Highcharts,echarts, Table, Form,jqueryui, jQDateRangeSlider,bootstrapdatetimepicker) {        
    var operas=0;
    var myVar1=null;
    Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1, //月份
                "d+": this.getDate(), //日
                "H+": this.getHours(), //小时
                "m+": this.getMinutes(), //分
                "s+": this.getSeconds(), //秒
                "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                "S": this.getMilliseconds() //毫秒
            };
            if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
    };
    var Controller = {
       
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resources/resc/addtabs',
                   /* add_url: 'reportdata/add',
                    edit_url: 'reportdata/edit',
                    del_url: 'reportdata/del',
                    multi_url: 'reportdata/multi',
                    testcycle: 'reportdata/testcycle',
                    detail: 'reportdata/detail',
                    exec: 'reportdata/exec',
                    stop: 'reportdata/stop',
                    realresults: 'reportdata/results',
                    historyresults: 'reportdata/historyresults',
                    realtotals: 'reportdata/realtotals',
                    table: 'missionlist',
                    select_probe: 'reportdata/select_probe',*/
                }
            }); 
            $('#info_left').datetimepicker({
            locale: moment.locale('zh-cn') //引入中文语言
            // language:  'zh-CN',  //日期
            });
            $('#info_right').datetimepicker({
              locale: moment.locale('zh-cn') //引入中文语言
            });
            $('#info_left1').datetimepicker({
            locale: moment.locale('zh-cn') //引入中文语言
            // language:  'zh-CN',  //日期
            });
            $('#info_right1').datetimepicker({
              locale: moment.locale('zh-cn') //引入中文语言
            });
            require('jquery-ui');
            require('jQDateRangeSlider');                     
            require(['jstree'], function () {                
                //全选和展开
                $(document).on("click", "#checkall", function () {
                    $("#channeltree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
                });
                $(document).on("click", "#expandall", function () {
                    $("#channeltree").jstree($(this).prop("checked") ? "open_all" : "close_all");
                });                
                $(".content").click();
                $('#channeltree').bind("changed.jstree", function (e, data) {                    
                    var treeNode = $('#channeltree').jstree(true).get_selected(true)[0]; //获取所有选中的节点对象
                    if(!treeNode){ 
                        operas='0';                                            
                        return false;
                    }
                    if(operas==treeNode.id){
                       return false;
                    }
                    operas=treeNode.id;
                    var treeNodeParents = treeNode.parents.slice(0,-1);
                    // console.log(treeNodeParents);
                    treeNodeParents.push(treeNode.original.id);
                    //operas==0
                    //console.log(treeNodeParents);
                    var getlevel = Controller.getlevel(treeNodeParents.join(","));
                    $(".titles").html(getlevel.ty_name+'-'+getlevel.tag_name+'详情');
                    $("#getlevel").val(JSON.stringify(getlevel));                    
                    $("#table3").bootstrapTable('destroy', {});
                    $("#table3").bootstrapTable('refresh', {});
                    $("#table").bootstrapTable('destroy', {});
                    $("#table").bootstrapTable('refresh', {});
                    var url = 'resources/resc/table3?name='+getlevel.ty_name+'-'+getlevel.tag_name+'&tag_id='+getlevel.is_sign+'&first_id='+getlevel.first_id+'&regtype='+getlevel.regtype;
                    // console.log(url);                   
                    initJQDateRange1();
                    initJQDateRange();
                    setTimeout(function () {
                       Controller.probequality(url);  
                    }, 200);                 
                    setTimeout(function () {
                       Controller.initCpuPageref1();
                    }, 200);
                    Controller.initCpuPageref();    
                    return false;
                });                
                // console.log(tagList);
                $('#channeltree').jstree({
                    "themes": {
                        "stripes": true,
                    },
                    "checkbox": {
                        "keep_selected_style": false,
                        "three_state": false, //如果想选择父节点时不全选子节点，就需要加上下面这句
                    },
                    "types": {
                        "channel": {
                            "icon": "fa fa-file-o",
                        },
                        "list": {
                            "icon": "fa fa-folder-o",  //非任务图标
                        },
                        "link": {
                            "icon": "fa fa-link",
                        },
                        "disabled": {
                            "check_node": false,
                            "uncheck_node": false
                        }
                    },
                    // "state"
                    'plugins': ["types", "checkbox","contextmenu"],
                    // "contextmenu":{
                    //     "items" : customMenu,
                    //     "select_node":false,//取消右击选中事件
                    // },                    
                    "core": {
                        // "multiple": true,
                        "multiple": false,//单选
                        'check_callback': true,
                        "data": tagList
                    }
                }).on('loaded.jstree', function(e, data){//树加载完执行
                    // console.log(111);
                    var treeNode = $('#channeltree').jstree(true).get_selected(true)[0]; //获取所有选中的节点对象
                    if(!treeNode){
                        //正常显示时间条
                        initJQDateRange();
                        initJQDateRange1();                
                        setTimeout(function () {                    
                            var url = 'resources/resc/table3';
                            Controller.probequality(url);
                            $("#regiontext").html("没有找到匹配的记录");                             
                        }, 700);
                    }
                });                
            });                       
            //刷新          
            $(document).on("click",".btn-labref",function(){
                $('#regiontext').show();
                $('#regionlinkname').html("");
                $('#regionlink').html(""); 
                Controller.initCpuPageref();
            });
            //刷新          
            $(document).on("click",".btn-second",function(){ 
                setTimeout(function () {
                    $("#table3").bootstrapTable('refresh');
                }, 700);
            });
            //刷新          
            $(document).on("click",".btn-third1",function(){ 
                $('#slider').dateRangeSlider('resize');
                setTimeout(function () {
                    $("#table").bootstrapTable('refresh');
                }, 700);
            });
            //  刷新树
            $(document).on('click',".btn-tree",function(){
                //  获取当前页面的utl
                var url =  window.location.href;
                location.reload(url);                 
            })
            //鼠标的移入移出
            document.getElementById('slider').onmouseover = function(){ 
                window.clearInterval(myVar1);
            };
            document.getElementById('slider1').onmouseover = function(){ 
                window.clearInterval(myVar1);
            };
            document.getElementById('slider1').onmouseout = function(){ 
                if(myVar1!=null){//判断计时器是否为空
                    window.clearInterval(myVar1);
                    myVar1=null;
                } 
                myVar1=setInterval(function () {
                    $('#slider').dateRangeSlider('resize');
                    $('#slider1').dateRangeSlider('resize');
                }, 100);
            };
            document.getElementById('slider').onmouseout = function(){ 
                if(myVar1!=null){//判断计时器是否为空
                    window.clearInterval(myVar1);
                    myVar1=null;
                } 
                myVar1=setInterval(function () {
                    $('#slider').dateRangeSlider('resize');
                    $('#slider1').dateRangeSlider('resize');
                }, 100);
            };
                  
            $(".flow_push_lable").click(function(obj){
                 $.ajax({
                    url: 'general/screens/index',
                    type:'post',
                    //data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                    dataType:'json',
                    success:function(json){
                        if(json.total<1){
                            Toastr.error("请先到屏幕维护-配置屏幕页面，配置屏幕名称");
                        }else{
                            var tag_id = $("#ids").html();
                            var getlevel_val = $("#getlevel").val();
                            var getlevel = eval('(' + getlevel_val + ')');                
                            //获取ID
                            var first_id = getlevel.first_id;
                            Fast.api.open("resources/tag/add_screen/ids/"+tag_id+"?regionid="+first_id+"&from=tag","选择屏幕");
                        }
                    }
                });
            });
            $("#slider").bind("userValuesChanged", function(e, data){
                var maxDateT=new Date(data.values.max).Format("yyyy-MM-dd HH:mm:ss");
                var minDateT=new Date(data.values.min).Format("yyyy-MM-dd HH:mm:ss");
                var periodname=dateDif(maxDateT,minDateT);
                if(periodname==1){
                    layer.msg('开始时间不能大于结束时间');
                }else{
                    $('#info_left').attr("timesdiff",minDateT);
                    $('#info_right').attr("timesdiff",maxDateT);
                    //设置右上方时间显示doc
                    $("#info_left").val(minDateT);
                    $("#info_right").val(maxDateT);
                    document.getElementById("info_period").innerText=periodname;
                    $("#table").bootstrapTable('refresh');
                    //Controller.initCpuPageref1();
                    // setTimeout(function () {
                    //     $("#table2").html("");
                    //     Controller.page1();
                    // }, 1000);
                    //Controller.page1();
                    
                }
            });
            $("#slider1").bind("userValuesChanged", function(e, data){

               var maxDateT=new Date(data.values.max).Format("yyyy-MM-dd HH:mm:ss");
               var minDateT=new Date(data.values.min).Format("yyyy-MM-dd HH:mm:ss");
               var periodname=dateDif(maxDateT,minDateT);
               
               if(periodname==1){
                    layer.msg('开始时间不能大于结束时间');
                }else{
                    $('#info_left1').attr("timesdiff",minDateT);
                    $('#info_right1').attr("timesdiff",maxDateT);
                    //设置右上方时间显示doc
                    $("#info_left1").val(minDateT);
                    $("#info_right1").val(maxDateT);
                    document.getElementById("info_period1").innerText=periodname;
                    Controller.initCpuPageref();
                }
               
            });
            // $("#statelink1").click(function(){
            //      if($(this).html()=="固定的"){
            //         $("#statelink1").html("动态的");
            //      }else{
            //         $("#statelink1").html("固定的");
            //      }
                 
            // });
            $(".period_state").click(function(){
                if($(this).html()=="固定的"){
                    $(this).html("动态的");
                }else{
                    $(this).html("固定的");
                }

            });
            // 时间轴左侧
            $(".link").click(function(){                            
                var flag=true;
                var hrefs=$('#labs>li.active>a').attr("href");                
                if(hrefs == "#firstlab"){
                    var aa=$("#slider1").dateRangeSlider("values");
                    var statelin=$("#statelink1").html();
                    var info_period_id="info_period1";
                    var link_id=".linkspa1>.link";
                }else if(hrefs == "#third1"){
                    var aa=$("#slider").dateRangeSlider("values");
                    var statelin=$("#statelink").html();
                    var info_period_id="info_period";
                    var link_id=".linkspa>.link";
                }
                //var aa=$("#slider").dateRangeSlider("values");
                var maxDateTime=new Date(aa.max);
                var minDateTime=new Date(aa.min);
                var currDate = new Date();
                // console.log(info_period_id);               
                if($(this).attr("nav") == undefined){//上方扩展时间轴                    
                    $(link_id).attr("style", 'font-size: 10px; font-weight: normal; text-decoration: underline;');
                    $(this).attr("style", 'font-size: 11px; font-weight: bold; text-decoration: none;');            
                    //时间转换，规则移动最小时间(扩大时间)
                    var changeValue = parseFloat("-"+$(this).attr("zoom"));                    
                    //设置进度条位置
                    minDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                    maxDateTime=new Date(aa.max);
                    minDateTime = new Date(minDateTime);
                    document.getElementById(info_period_id).innerText =this.innerText;
                    $("#"+info_period_id).attr("timesdiff",this.innerText);
                }else{ //左移右移事件             
                    //时间转换，加一天
                    var changeValue = parseFloat($(this).attr("nav"));
                    if(statelin=="动态的"){//时间间隔改变
                        //设置进度条位置
                        if(changeValue>0){
                            maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                            maxDateTime=new Date(maxDateTime);
                            if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                layer.msg('调整时间超出范围');
                                flag = false;
                                //maxDateTime=currDate;
                            }
                        }else{
                            minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                            minDateTime=new Date(minDateTime);
                            var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr1['所有']);
                            if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                               layer.msg('调整时间超出范围');
                               //minDateTime=new Date(currDatemin);
                               flag = false;
                            }
                        }
                        if (flag == true){
                            var periodname=dateDif(maxDateTime,minDateTime);
                            if(periodname==1){
                                layer.msg('开始时间不能大于结束时间');
                                flag = false;
                            }else{
                                document.getElementById(info_period_id).innerText=periodname;
                            }
                        }
                    }else{//时间间隔固定
                            maxDateTime=maxDateTime.setSeconds(maxDateTime.getSeconds()+changeValue);
                            maxDateTime=new Date(maxDateTime);
                            if(new Date(currDate).getTime()<new Date(maxDateTime).getTime()){
                                layer.msg('调整时间超出范围');
                                flag = false;
                            }
                            minDateTime=minDateTime.setSeconds(minDateTime.getSeconds()+changeValue);
                            minDateTime=new Date(minDateTime);
                            var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr1['所有']);
                            if(new Date(currDatemin).getTime()>new Date(minDateTime).getTime()){
                               layer.msg('调整时间超出范围'); 
                               flag = false;
                            }
                    }    
                                           
                }    

                if (flag == true){
                    if(hrefs == "#firstlab"){
                        $("#slider1").dateRangeSlider("min", minDateTime);
                        $("#slider1").dateRangeSlider("max", maxDateTime);
                        //设置右上方时间显示doc
                        $('#info_left1').attr("timesdiff",minDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        $('#info_right1').attr("timesdiff",maxDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        //设置右上方时间显示doc
                        $("#info_left1").val(minDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        $("#info_right1").val(maxDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        Controller.initCpuPageref();
                    }else if(hrefs == "#third1"){                        
                        $("#slider").dateRangeSlider("min", minDateTime);
                        $("#slider").dateRangeSlider("max", maxDateTime);
                        //设置右上方时间显示doc
                        $('#info_left').attr("timesdiff",minDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        $('#info_right').attr("timesdiff",maxDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        //设置右上方时间显示doc
                        $("#info_left").val(minDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        $("#info_right").val(maxDateTime.Format("yyyy-MM-dd HH:mm:ss"));
                        //Controller.initCpuPageref1();
                        $("#table").bootstrapTable('refresh');
                    }
                }

            });
             

            var dateDif=function(endTime,startTime){
                //var date = enddate.getTime() - startdate.getTime();
                var usedTime  = new Date(endTime).getTime() - new Date(startTime).getTime();
                var timename='';
                if(usedTime<0){
                    timename=1;
                }else{
                    var year = Math.floor(usedTime / (365 *24 * 3600 * 1000)); // 计算出年数
                    var leavel = usedTime % (365 *24 * 3600 * 1000); // 计算年数后剩余的时间
                    
                    var months = Math.floor(leavel / (30 *24 * 3600 * 1000)); // 计算出月数
                    var leavel1 = leavel % (30 *24 * 3600 * 1000); // 计算月数后剩余的时间
                    
                    var days = Math.floor(leavel1 / (24 * 3600 * 1000)); // 计算出天数
                    var leavel2 = leavel1 % (24 * 3600 * 1000); // 计算天数后剩余的时间
                    
                    var hours = Math.floor(leavel2 / (3600 * 1000)); // 计算剩余的小时数
                    var leavel3 = leavel2 % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
                    
                    var minutes = Math.floor(leavel3 / (60 * 1000)); // 计算剩余的分钟数
                    var leavel4 = leavel3 % (60 * 1000); // 计算剩余分钟后剩余的毫秒数
                    
                    var seconds = Math.floor(leavel4 / (1000)); // 计算剩余的秒数
                    
                    var time1= year+'年'+months+'月' +days+ '天' + hours + '时' + minutes + '分';
                    if(year!=0){timename=year+'y';}
                    if(months!=0){timename=timename+' '+months+'m';}
                    if(days!=0){timename=timename+' '+days+'d';}
                    if(hours!=0){timename=timename+' '+hours+'h';}
                }
                return timename;
            };
            var initJQDateRange = function(){
                //require(['jquery-ui', 'jQDateRangeSlider'], function () {
                require('jquery-ui');
                require('jQDateRangeSlider');
                (function abc() {    
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);
                    
                    $("#slider1").dateRangeSlider();
                    $('#slider1').dateRangeSlider('resize');
                    $("#slider1").dateRangeSlider("bounds", new Date(start_date.setSeconds(start_date.getSeconds()-zoomListarr1['所有'])), new Date(curDate));
                    $("#slider1").dateRangeSlider("min", new Date(end_date.setSeconds(end_date.getSeconds()-zoomListarr1['1d'])));
                    $("#slider1").dateRangeSlider("max", new Date(curDate));
                    $('.links>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: underline;');
                    var a=$('.links>.link');
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.links>.link')[i].style.fontSize="11px";
                            $('.links>.link')[i].style.fontWeight="bold";
                            $('.links>.link')[i].style.textDecoration="none";
                        }
                    }
                    document.getElementById("info_period1").innerText ='1d';
                    //document.getElementById("xianz").style.display="";
                    $('#info_left1').attr("timesdiff",end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_right1').attr("timesdiff",curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    //设置右上方时间显示doc
                    $("#info_left1").val(end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#info_right1").val(curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_left1').attr("placeholder",end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_right1').attr("placeholder",curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    
                    //$(".ui-rangeSlider-handle.ui-rangeSlider-rightHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    //$(".ui-rangeSlider-handle.ui-rangeSlider-leftHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $(".ui-rangeSlider-label.ui-rangeSlider-rightLabel")[0].style.display="none";
                    $(".ui-rangeSlider-label.ui-rangeSlider-leftLabel")[0].style.display="none";
                    window.addEventListener("resize", function () {
                        $('#slider1').dateRangeSlider('resize');
                    });
                    if(myVar1!=null){//判断计时器是否为空
                        window.clearInterval(myVar1);
                        myVar1=null;
                    } 
                    myVar1=setInterval(function () {
                        //if ($("#"+if_ids).width() != $("#"+if_ids+" canvas").width() && $("#"+if_ids+" canvas").width() < $("#"+if_ids).width()) {
                            $('#slider1').dateRangeSlider('resize');
                            $('#slider').dateRangeSlider('resize');
                        //}
                    }, 100);
                })();
            };
            var initJQDateRange1 = function(){
                //require(['jquery-ui', 'jQDateRangeSlider'], function () {
                require('jquery-ui');    
                require('jQDateRangeSlider');
                (function abc() {     
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);
                    $("#slider").dateRangeSlider();
                    $("#slider").dateRangeSlider("bounds", new Date(start_date.setSeconds(start_date.getSeconds()-zoomListarr1['所有'])), new Date(curDate));
                    $("#slider").dateRangeSlider("min", new Date(end_date.setSeconds(end_date.getSeconds()-zoomListarr1['1d'])));
                    $("#slider").dateRangeSlider("max", new Date(curDate));
                    $('.linkspa>.link').attr("style", 'font-size: 10px; font-weight: normal; text-decoration: underline;');
                    var a=$('.linkspa>.link');
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.linkspa>.link')[i].style.fontSize="11px";
                            $('.linkspa>.link')[i].style.fontWeight="bold";
                            $('.linkspa>.link')[i].style.textDecoration="none";
                        }
                    }
                    //$('#xianz').style.display="";
                    document.getElementById("info_period").innerText ='1d';
                    $('#info_left').attr("timesdiff",end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_right').attr("timesdiff",curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#info_left").val(end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#info_right").val(curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_left').attr("placeholder",end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $('#info_right').attr("placeholder",curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    //$(".ui-rangeSlider-handle.ui-rangeSlider-rightHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    //$(".ui-rangeSlider-handle.ui-rangeSlider-leftHandle")[0].style.background="url(/assets/img/dateSilderArr.png) no-repeat";
                    $("#slider >.ui-rangeSlider-label.ui-rangeSlider-rightLabel")[0].style.display="none";
                    $("#slider >.ui-rangeSlider-label.ui-rangeSlider-leftLabel")[0].style.display="none";
                    window.addEventListener("resize", function () {
                        $('#slider').dateRangeSlider('resize');
                    });

                })();
            };
            // 时间轴右侧时间框
            $(".datetimepicker").blur( function(){ 
                var flagchang = true;
                var timen = $(this).val();
                var id_str = $(this).attr('id');
                var timesdiff_str = $(this).attr('timesdiff');
                
                var hrefs=$('#labs>li.active>a').attr("href");
                if(hrefs == "#firstlab"){
                    var  maxDateTh=$('#info_right1').val();
                    var  minDateTh=$('#info_left1').val();
                    var  statelink=$("#statelink1").html();
                    var  info_period_id="info_period1";
                    var  slider_id="slider1";
                    var  info_left_id="info_left1";
                    var  info_right_id="info_right1";
                    var  link_id=".linkspa1>.link"; 
                }else if(hrefs == "#third1"){
                    var  maxDateTh=$('#info_right').val();
                    var  minDateTh=$('#info_left').val();
                    var  statelink=$("#statelink").html();
                    var  info_period_id="info_period";
                    var  slider_id="slider";
                    var  info_left_id="info_left";
                    var  info_right_id="info_right";
                    var  link_id=".linkspa>.link"; 
                }
                if(timen==null ||timen.indexOf("NaN") != -1 ||timesdiff_str.indexOf("NaN") != -1){
                    layer.msg('调整时间格式错误');
                    var curDate = new Date();     
                    var start_date=new Date(curDate);     
                    var end_date=new Date(curDate);

                    var mint=new Date(end_date.setSeconds(end_date.getSeconds()-zoomListarr1['1d']));
                    $("#"+slider_id).dateRangeSlider("values", mint, new Date(curDate));
                    $("#"+slider_id).dateRangeSlider('resize');
                    $("#"+info_left_id).val(end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#"+info_right_id).val(curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#"+info_left_id).attr("placeholder",end_date.Format("yyyy-MM-dd HH:mm:ss"));
                    $("#"+info_right_id).attr("placeholder",curDate.Format("yyyy-MM-dd HH:mm:ss"));
                    $(link_id).attr("style", 'font-size: 10px; font-weight: normal; text-decoration: underline;');
                    var a=$(link_id);
                    for (var i = 0; i < a.length; i++) {
                        if(a[i].innerText=='1d'){
                            $('.links>.link')[i].style.fontSize="11px";
                            $('.links>.link')[i].style.fontWeight="bold";
                            $('.links>.link')[i].style.textDecoration="none";
                        }
                    }
                    document.getElementById(info_period_id).innerText ='1d';
                    if(hrefs == "#firstlab"){                       
                        Controller.initCpuPageref();
                    }else if(hrefs == "#third1"){
                        //Controller.initCpuPageref1();
                        $("#table").bootstrapTable('refresh');
                    }
                    return false;
                }
               
                if(timen!=timesdiff_str&&timen.indexOf("NaN") == -1 ){
                    var currDate = new Date();
                    var dateTime=Date.parse(new Date(timen));
                    //var dateaa=new Date(dateTime).Format("yyyy-MM-dd HH:mm:ss");//调整的时间
                    if(new Date(currDate).getTime()<dateTime){
                        layer.msg('调整时间超出范围');
                        flagchang = false;
                    }else{
                        if(statelink=="动态的"){//时间间隔改变
                            var periodname=dateDif(maxDateTh,minDateTh);
                            if(periodname==1){
                                layer.msg('开始时间不能大于结束时间');
                                flagchang = false;
                            }
                        }else{//时间间隔固定
                           var aa=$("#"+info_period_id).attr('timesdiff');
                           var changeV=zoomListarr1[aa];
                           var tmpMaxDateTh = new Date(maxDateTh);
                           maxDateTh=new Date(maxDateTh);
                           var tmpMinDateTh = new Date(minDateTh);
                           minDateTh=new Date(minDateTh);
                            //console.log(changeV);
                           if(id_str.indexOf("info_left") !=-1){//根据最小时间自动改变最大时间
                                maxDateTh=tmpMinDateTh.setSeconds(tmpMinDateTh.getSeconds()+parseInt(changeV));
                                maxDateTh=new Date(maxDateTh);
                                if(new Date(currDate).getTime()<new Date(maxDateTh).getTime()){
                                    layer.msg('调整时间超出范围');
                                    flagchang = false;
                                }
                            }else{ //根据最大时间自动改变最小时间   
                                minDateTh=tmpMaxDateTh.setSeconds(tmpMaxDateTh.getSeconds()-parseInt(changeV));
                                minDateTh=new Date(minDateTh);
                            }
                        }
                    }
                    // return false;
                    var currDatemin = currDate.setSeconds(currDate.getSeconds()-zoomListarr1['所有']);
                    if(new Date(currDatemin).getTime()>new Date(minDateTh).getTime()&&id_str.indexOf(info_left_id) != '-1'){
                       layer.msg('调整时间超出范围'); 
                       flagchang = false;
                    }
                    //console.log(flagchang);
                    if (flagchang == true){
                        if(statelink=="动态的"){//时间间隔改变
                            document.getElementById(info_period_id).innerText=periodname;
                        }
                        //console.log(hrefs);
                        if(hrefs == "#firstlab"){
                            $("#slider1").dateRangeSlider("min", new Date(minDateTh));
                            $("#slider1").dateRangeSlider("max", new Date(maxDateTh));
                            //设置右上方时间显示doc
                            $('#info_left1').attr("timesdiff",new Date(minDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            $('#info_right1').attr("timesdiff",new Date(maxDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            $("#info_left1").val(new Date(minDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            $("#info_right1").val(new Date(maxDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            Controller.initCpuPageref();
                        }else if(hrefs == "#third1"){
                            //console.log(123);
                            $("#slider").dateRangeSlider("min", new Date(minDateTh));
                            $("#slider").dateRangeSlider("max", new Date(maxDateTh));
                            $('#info_left').attr("timesdiff",new Date(minDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            $('#info_right').attr("timesdiff",new Date(maxDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            //设置右上方时间显示doc
                            $("#info_left").val(new Date(minDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            $("#info_right").val(new Date(maxDateTh).Format("yyyy-MM-dd HH:mm:ss"));
                            //Controller.initCpuPageref1();
                            $("#table").bootstrapTable('refresh');
                        }

                          
                         
                      }else{
                          $(this).val(timesdiff_str);
                      }
                }
            });
            
            // 左侧树无数据处理
            if(tagList.length <1){
                //正常显示时间条
                initJQDateRange();
                initJQDateRange1();                
                setTimeout(function () {                    
                    var url = 'resources/resc/table3';
                    Controller.probequality(url);
                    $("#regiontext").html("没有找到匹配的记录");
                }, 700);
            };
            $(document).on("click",".basname",function(obj){
                var btn_obj = $(this);
                var tag_id = $(btn_obj).attr('tag_id'); 
                var tag_name = $(btn_obj).attr('tag_name'); 
                var tag_type = $(btn_obj).attr('tag_type'); 
                var url = window.location.host+'/screen/drawing/detail?id='+tag_id+'&name='+tag_name+'&type='+tag_type;        
                window.open('http://'+url);
            })
            // 为表格绑定事件
            // Table.api.bindevent(table);            
        },
        //  设备接口列表               
        probequality:function(url,is_type,name,tabs_text,level,subset_ids,children_ids,time_text,selected_id){           
            var table3 = $("#table3");            
            table3.bootstrapTable({
                url: url,
                extend: {
                    //edit_url: 'resources/resc/if_edit',
                    table: 'device_if',
                },
                toolbar: '#toolbar3',
                sortName: 'a.id',
                search: false,
                searchFormVisible: false,
                pageSize:50,
                columns: [
                    [
                        {field: 'a.id', title:__('ID'),formatter: function(value,row,index){
                                return row.id;
                        }},
                        {field: 'b.name', title: __('设备名'),operate:false,placeholder: __('模糊查询'),
                            formatter: function(value,row,index){
                                if(row.devicename){
                                    return row.devicename;
                                }else{
                                    return '-';
                                }
                            }
                        },
                        {field: 'b.ip', title: __('设备Ip'),operate:false,placeholder: __('模糊查询'),formatter: function(value,row,index){
                                return row.deviceip;
                        }},
                        // {field: 'areaname', title: __('Area_id'),operate:false,placeholder: __('模糊查询')},
                        // {field: 'regionname', title: __('Region_id'),operate:false,placeholder: __('模糊查询')},
                        {field: 'IfName', title: __('接口名称'),operate: 'LIKE %...%',formatter:function(data,full){
                            if(data == "" || data == null){
                                return "-";
                            }else{
                                return data;
                            }
                        }},
                        {field: 'IfDescr', title: __('接口描述'),operate: 'LIKE %...%'},
                        {field: 'IfAlias', title: __('接口描述别名'),operate: 'LIKE %...%',formatter:function(data,full){
                            if(data == "" || data == null){
                                return "-";
                            }else{
                                return data;
                            }
                        }},
                        {field: 'IfIndex', title: __('接口编号')},
                        {field: 'c.type', title: __('流入/流出'),searchList: {"OutSpeed":__('流出'),"InSpeed":__('流入')},operate:'LIKE %...%' ,formatter:function(data,full){
                            if(full.type == 'OutSpeed'){
                                return '流出';
                            }else if(full.type == 'InSpeed'){
                                return '流入';
                            }else{
                                return '流入/流出';
                            }
                        }},
                        /*{field: 'type', title: __('Type'),operate:false,formatter : Controller.api.formatter.tag,table: table3, events:{
                                'click .labelhref':function(e,value,row){
                                    let ids=row.device_id;
                                    let name=$(this).attr("name");
                                    layer.open({
                                        offset: '0px', //右下角弹出
                                        type: 2,
                                        area: ['100%','100%'],
                                        fix: false, //不固定
                                        maxmin: true, //显示或者隐藏缩小 放大 按钮
                                        shadeClose: false,//锁定当前页面必须点 X 才能关闭此页面
                                        shade:0.4,
                                        title: '标签详情',
                                        content: '/admin/resources/resc/label' + "?ids=" + ids+"&name="+name
                                    });
                                }
                           }
                        },*///formatter: Table.api.formatter.normal
                        /*{field: 'IfOperStatus', title: __('接口状态'), searchList: {"1":__('在线'),"2":__('不在线')},formatter:function(data,full){
                            if(data == "1"){
                                return  '<span style="color:green">在线</span>';
                            }else if(data == "2"){
                                return '<span style="color:gray">不在线</span>';
                            }else{
                                return data;
                            }
                        }},*/
                        {field: 'IfOperStatus', title: __('接口状态'), searchList: {"1":__('在线'),"2":__('不在线'),"3":__('测试'),"4":__('未知'),"5":__('休眠'),"6":__('不显示'),"7":__('底层不在线'),"99":__('过期')},formatter:function(data,full){
                            if(data == "1"){
                                return  '<span style="color:green">在线</span>';
                            }else if(data == "2"){
                                return '<span style="color:gray">不在线</span>';
                            }else if(data == "3"){
                                return '<span style="color:gray">测试</span>';
                            }else if(data == "4"){
                                return '<span style="color:gray">未知</span>';
                            }else if(data == "5"){
                                return '<span style="color:gray">休眠</span>';
                            }else if(data == "6"){
                                return '<span style="color:gray">不显示</span>';
                            }else if(data == "99"){
                                return '<span style="color:gray">过期</span>';
                            }else{
                                return '<span style="color:gray">底层不在线</span>';
                                
                            }
                        }},
                        {field: 'operate', title: '标签操作', table: table3, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,buttons: [                            
                        // {
                        //     name: 'detail',
                        //     text: '绑定',
                        //     title: '绑定标签',
                        //     classname: 'btn btn-xs btn-success btn-dialog',
                        //     icon: 'fa fa-plus',
                        //     url: 'resources/resc/if_edit',                                
                        // },
                        {
                            name: 'if_del',
                            text: '解绑',
                            title: '解绑标签',
                            classname: 'btn btn-xs btn-danger btn-dialog',
                            icon: 'fa fa-trash',
                            url: 'resources/resc/if_del',                                
                        },
                        {
                            name: 'detail',
                            text: '流量图',
                            title: '查看流量图',
                            classname: 'btn btn-xs btn-info',
                            icon: 'fa fa-list',
                            extend:"target='_blank'",//打开新的浏览器页面，而不是弹窗，更不是选项卡，是新的浏览器标签
                            //url: '/screen/drawing/detail/type/1',
                            url:function(row){
                                return '/screen/drawing/detail?ids='+row.id+'&type=1';
                            }
                        },
                        {
                            name: 'dev_detail',
                            text: '设备监控',
                            title: '设备监控',
                            classname: 'btn btn-xs btn-info btn-addtabs',
                            icon: 'fa fa-list',
                            // extend:"target='_blank'",//打开新的浏览器页面，而不是弹窗，更不是选项卡，是新的浏览器标签
                            // url: 'region/device/detail/ids/{device_id}',
                            url:function(row){
                                // console.log(row);
                                return 'region/device/index/ids/'+row.device_id;
                            }                             
                        }
                        ]}
                    ]
                ]
            });

            // 为表格3绑定事件
            Table.api.bindevent(table3);         
        }, 
        //  总流量趋势
        initCpuPageref:function(){
            var starttime3 = $("#info_left1").val();
            var endtime3=$("#info_right1").val();
            var gradename3='';
            var getlevel_val = $("#getlevel").val();
            var getlevel = eval('(' + getlevel_val + ')');                
            //获取ID
            var ids = getlevel.is_sign;
            var names = getlevel.ty_name+'__'+getlevel.tag_name;
            var first_id = getlevel.first_id;
            $("#ids").html(ids);
            $.ajax({
                url: 'resources/resc/regionline',
                type:'post',
                data: {ids:ids,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3,first_id:first_id},
                dataType:'json',
                success:function(json){
                    if(json.length<1){
                        $('#regiontext').show();
                        $('#regiontext').html("没有找到匹配的记录");
                        $("#flow_pu").hide();
                    }else{
                        $('#regiontext').hide();
                        $('#regiontext').html("正在努力地加载数据中，请稍后......");
                        $("#flow_pu").show();
                        for(var item of json) { // item代表数组里面的元素    
                            //$("#flow_push_lable").attr("tag_id", item.tag_id); 
                            $("#regionlinkname").attr("tag_id", item.tag_id);
                            $("#regionlinkname").attr("tag_name", item.name);
                            $("#regionlinkname").attr("tag_type", '3');
                            Controller.piechart(item, item.name, "regionlink","regionlinkname");
                        }
                    }
                    $('#slider1').dateRangeSlider('resize');
                }
            });
        },
        //  流量趋势
        initCpuPageref1:function(){
            var starttime3 = $("#info_left").val();
            var endtime3=$("#info_right").val();
            $('#slider').dateRangeSlider('resize');
            Template.helper("Moment", Moment);
            var table = $("#table");            
            var getlevel_val = $("#getlevel").val();
            var getlevel = eval('(' + getlevel_val + ')');                
            //获取ID
            var ids = getlevel.is_sign;
            var first_id = getlevel.first_id;
            var regtype = getlevel.regtype;
            $("#ids").html(ids);
            var id = $("#ids").html();                        
            table.bootstrapTable('refresh');
            table.bootstrapTable('destroy');
            // 初始化表格
            table.bootstrapTable({
                url: 'region/tag/table',
                //url: 'region/tag/table?ids='+ids+'&starttime='+starttime3+'&endtime='+endtime3+'&first_id='+first_id+'&regtype='+regtype,
                templateView: true,
                toolbar: '#toolbar',
                sortName: 'b.id',
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID', operate: false},
                        //模糊搜索
                        {field: 'title', title: __('Title'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符', style: 'width:200px'},
                        {field: 'IfDescr', title: __('IfDescr'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'IfAlias', title: __('接口描述别名'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'IfIndex', title: __('接口编号'),operate:'LIKE',placeholder: __('模糊查询')},
                        {field: 'IfOperStatus', title: __('IfOperStatus'), searchList: {"1":__('在线'),"2":__('不在线'),"3":__('测试'),"4":__('未知'),"5":__('休眠'),"6":__('不显示'),"7":__('底层不在线')},formatter:function(data,full){
                                if(data == "1"){
                                    return  '<span style="color:green">在线</span>';
                                }else if(data == "2"){
                                    return '<span style="color:gray">不在线</span>';
                                }else if(data == "3"){
                                    return '<span style="color:gray">测试</span>';
                                }else if(data == "4"){
                                    return '<span style="color:gray">未知</span>';
                                }else if(data == "5"){
                                    return '<span style="color:gray">休眠</span>';
                                }else if(data == "6"){
                                    return '<span style="color:gray">不显示</span>';
                                }else{
                                    return '<span style="color:gray">底层不在线</span>';
                                    
                                }
                        }},
                        {field: 'createtime', title: __('Create time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ],
                ],
                //禁用默认搜索
                showExport: false,
                showToggle: false,
                showColumns: false,
                search: false,
                //启用普通表单搜索
                commonSearch: false,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: false,
                //分页大小
                pageSize: 12,
                queryParams: function queryParams(params){
                    params.ids= $("#ids").html();
                    params.starttime= $("#info_left").val();
                    params.endtime= $("#info_right").val();
                    params.first_id=first_id;
                    params.regtype=regtype;
                   return params; 
                }

            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            //指定搜索条件
            $(document).on("click", ".btn-toggle-view", function () {
                var options = table.bootstrapTable('getOptions');
                table.bootstrapTable('refreshOptions', {templateView: !options.templateView});
            });
            table.on('post-body.bs.table', function (e, data) {
                $(".echart").each(function () {
                    var textareas=$('textarea', this).val();
                    if(textareas=='undefined'||textareas==''||textareas==null){
                        return false;
                    }
                    var json = JSON.parse(textareas);
                    var if_ids=json.id;
                    //  点击标题跳转到单个图的页面
                    $("#flow_"+if_ids).on('click',function(){
                        Controller.singleDetails(if_ids,json.name,'1');
                    })
                    // 基于准备好的dom，初始化echarts实例
                    var myCharts = echarts.init($(this)[0], 'walden');
                    // 指定图表的配置项和数据
                    var option = {
                        /*title: {
                            text: '',
                            subtext: ''
                        },*/
                        tooltip: {
                            trigger: 'axis',
                           /* position: function (p) {   //其中p为当前鼠标的位置
                                return [p[0] + 10, p[1] - 10];
                            },*/
                            position: ['20%', '30%'],
                            //position:'inside',
                            formatter:function(params, ticket, callback){
                                var tipString = params[0].name + "<br />";
                                var indexColor;
                                if(id.indexOf("property") != -1 ){
                                    for (var i = 0, length = params.length; i < length; i++) {
                                        if(params[i].value==""||params[i].value==null){
                                            var item_val_str = 0+" %";
                                        }else{
                                            var item_val_str = params[i].value.toFixed(2)+" %";
                                        }
                                        indexColor = params[i].color;
                                        tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                                        tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                                    }
                                }else{
                                    for (var i = 0, length = params.length; i < length; i++) {
                                        var item_val = params[i].value;
                                        if(item_val < 1000){
                                            if(item_val==""||item_val==null){
                                                var item_val_str = 0+" bps";
                                            }else{
                                                var item_val_str = item_val.toFixed(2)+" bps";
                                            }
                                           //var item_val_str = item_val.toFixed(2)+" bps";
                                        }else if(1000 < item_val && item_val < 1000 * 1000){
                                           var item_val_str = (item_val/(1000)).toFixed(2)+"Kbps";
                                        }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                                           var item_val_str = (item_val/(1000*1000)).toFixed(2)+"Mbps";
                                        }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                                           var item_val_str = (item_val/(1000*1000*1000)).toFixed(2)+"Gbps";
                                        }
                                        indexColor = params[i].color;
                                        tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                                        tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value / 1000 / 1000 + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                                    }
                                }
                                return tipString;
                                
                            }
                        },
                        legend: {
                            x: 'center',
                            y:30,
                            data:['入流量','出流量']
                         },
                        toolbox: {
                            /*show: false,
                            feature: {
                                magicType: {show: true, type: ['stack', 'tiled']},
                                saveAsImage: {show: true}
                            },*/
                            feature: {
                                 myTool1: {
                                    show: true,
                                    title: '推送到屏幕',
                                    icon:'image:///assets/img/copy.png',
                                    //icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
                                    onclick: function (){
                                        $.ajax({
                                            url: 'general/screens/index',
                                            type:'post',
                                            //data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                                            dataType:'json',
                                            success:function(json){
                                                if(json.total<1){
                                                    Toastr.error("请先到屏幕维护-配置屏幕页面，配置屏幕名称");
                                                }else{
                                                    Fast.api.open("resources/tag/add_screen/ids/"+if_ids+"?regionid="+getlevel.first_id+"&from=interface","选择屏幕");
                                                }
                                            }
                                        });
                                    }
                                },
                                dataZoom: {
                                    yAxisIndex: 'none'
                                },
                                restore: {},
                                saveAsImage: {}
                            }
                        },
                        xAxis: {
                            type: 'category',
                            boundaryGap: false,
                            data: json.xAxis,
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    type: 'dashed'
                                }
                            }
                        },
                        yAxis: {
                            type: 'value',
                            boundaryGap: [0, '100%'],
                            axisLabel: {
                                formatter:function(item_val){
                                    if(id.indexOf("property") != -1 ){
                                        return Math.floor(item_val) + ' %';
                                    }else{
                                        if(item_val < 1000){
                                            return Math.floor(item_val)+" bps";
                                        }else if(1000 < item_val && item_val < 1000 * 1000){
                                            return Math.floor(item_val/(1000))+"Kbps";
                                        }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                                            return Math.floor(item_val/(1000*1000))+"Mbps";
                                        }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                                            return Math.floor(item_val/(1000*1000*1000))+"Gbps";
                                        }
                                    }
                                },
                            },
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    type: 'dashed'
                                }
                            }
                        },
                       
                        /*dataZoom: [{
                            show:true,
                            //type: 'inside',//鼠标滚动影响图标拖动
                            type: 'slider',
                            start: 85,
                            end: 100,
                            zoomOnMouseWheel:false,
                        }, {
                            start: 0,
                            end: 10,
                            handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                            handleSize: '80%',
                            handleStyle: {
                                color: '#fff',
                                shadowBlur: 3,
                                shadowColor: 'rgba(0, 0, 0, 0.6)',
                                shadowOffsetX: 2,
                                shadowOffsetY: 2
                            }
                        }],
                        grid: [{
                                left: 'left',
                                width: '96%'
                                //top: 'top',
                                //right: '10',
                                //bottom: 30
                        }],*/
                        series: [{
                                name: json.series[0].name,
                                type: 'line',
                                smooth: true,
                                symbol: 'none',
                                sampling: 'average',
                                /*itemStyle: {
                                    color: 'rgb(255, 70, 131)'
                                },
                                areaStyle: {
                                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                        offset: 0,
                                        color: 'rgb(255, 158, 68)'
                                    }, {
                                        offset: 1,
                                        color: 'rgb(255, 70, 131)'
                                    }])
                                },*/
                                itemStyle: {
                                    normal: {
                                        //color: '#00aa00',
                                        //color:'linear-gradient(top, white, red)',
                                        opacity: 1,
                                        barBorderRadius: 5,
                                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                            offset: 1,
                                            color: '#c8edc8'
                                        }, {
                                            offset: 0,
                                            color: '#00aa00'
                                        }])

                                    }
                                },
                                areaStyle: {
                                    normal: {
                                    }
                                },
                                lineStyle: {
                                    normal: {
                                        color: '#047d04',
                                        width: 1.5
                                    }
                                },
                                data: json.series[0].data
                            },{
                                name:json.series[1].name,
                                type:'line',
                                smooth:true,
                                symbol: 'none',
                                sampling: 'average',
                                itemStyle: {
                                    normal: {
                                        //color: '#002a97',
                                        //color:'linear-gradient(top, white, red)',
                                        opacity: 1,
                                        barBorderRadius: 5,

                                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                            offset: 1,
                                            color: '#9a9aff'
                                        }, {
                                            offset: 0,
                                            color: '#002a97'
                                        }])
                                    }
                                },
                                /*itemStyle: {
                                    normal: {
                                        color: '#3C3089',
                                        opacity: 1,
                                        barBorderRadius: 5,
                                    }
                                },*/
                                areaStyle: {
                                    normal: {
                                    },
                                },
                                lineStyle: {
                                    normal: {
                                        color: '#03037b',
                                        width: 1.5
                                    }
                                },
                                data:json.series[1].data
                            }]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myCharts.clear();
                    myCharts.setOption(option);
                    window.addEventListener("resize", function () {
                        myCharts.resize();
                    });
                    myCharts.dispatchAction({ // 默认启动 toolbox 中 dataZoom 的区域缩放状态
                        type: "takeGlobalCursor",
                        key: "dataZoomSelect",
                        dataZoomSelectActive: true
                    });
                    setInterval(function () {
                        if ($("#"+if_ids).width() != $("#"+if_ids+" canvas").width() && $("#"+if_ids+" canvas").width() < $("#"+if_ids).width()) {
                            myCharts.resize();
                        }
                    }, 700);
                });
            });
        },
        //  流量趋势包含分页
        page:function(type){
            var starttime='';
            var curDate = new Date();
            var start_date = new Date(curDate.getTime() - 24*60*60*1000).Format("yyyy-MM-dd HH:mm");//前一天
            var end_date = new Date().Format("yyyy-MM-dd HH:mm");
            if(type=='1'){//重置1
               $("#start_date").val(start_date);
               $("#end_date").val(end_date);
                document.getElementById("gradename")[0].selected=true;
                $("#ifIndex").val("").trigger("change");//清空
                $('.selectpicker').selectpicker('refresh'); 
            }
            if($("#start_date").val() != ''){
               starttime=$("#start_date").val();
            }else{
                starttime=start_date;
            }
            var endtime='';
            if($("#end_date").val() != ''){
               endtime=$("#end_date").val();
            }else{
                endtime=end_date;
            }
            if (endtime < starttime) {
                  layer.alert('结束时间应大于开始时间',{offset: ['200px', '150px']});
                return false;
            }
            var gradename='';
            if($("#gradename").val() != "") {
               gradename=$("#gradename").find("option:selected").val();
            }
            var alias='';
            if($("#alias").val() != "") {
                alias=$("#alias").val();
            }
            var desc='';
            if($("#desc").val() != "") {
                desc=$("#desc").val();
            }
            var ifIndex = "";
            if ($("#ifIndex").val() != "") {
                ifIndex=$("#ifIndex").val();                   
            }                
            var getlevel_val = $("#getlevel").val();
            var getlevel = eval('(' + getlevel_val + ')');                
            //获取ID
            var a = getlevel.is_sign;
            //先获取总页数画图
            $.ajax({
                url: 'resources/resc/fenye',
                type:'post',
                data: {alias:alias,desc:desc,ifIndex:ifIndex,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                dataType:'json',
                success:function(json){      
                    //console.log(json) ;//没有数据   
                    if(json === -1){
                        $n = 1;
                        while($n<11){
                            $("#basedlink_"+$n).hide();
                            $("#flow_push_"+$n).hide();
                            $n++;
                        }
                        $("#pagination").hide();
                    }else{
                        $("#pagination").show();
                       var pageObj = new Page({
                            id: 'pagination',
                            pageTotal: json.pageTotal, //必填,总页数
                            pageAmount: 10,  //每页多少条
                            dataTotal: json.dataTotal, //总共多少条数据
                            curPage:1, //初始页码,不填默认为1
                            pageSize: 10, //分页个数,不填默认为5
                            showPageTotalFlag:true, //是否显示数据统计,不填默认不显示
                            showSkipInputFlag:true, //是否支持跳转,不填默认不显示
                            getPage: function (page) {
                               //获取ID
                                $.ajax({
                                    url: 'resources/resc/chart_data',
                                    type:'post',
                                    data: {alias:alias,desc:desc,ifIndex:ifIndex,page:page,ids:a,starttime:starttime,endtime:endtime,gradename:gradename},
                                    dataType:'json',
                                    success:function(json){
                                        $('#slider1').dateRangeSlider('resize');
                                        $n = 1;
                                        for(var item of json) { // item代表数组里面的元素
                                            $("#basedlink_"+$n).show();
                                            $("#flow_push_"+$n).show();
                                            $("#flow_push_"+$n).attr("if_id", item.id);
                                            Controller.piechart(item, item.name, "basedlink_"+$n,"basedlinkname_"+$n);
                                            $n++;  
                                        };

                                        while($n<11){
                                            $("#basedlink_"+$n).hide();
                                            $("#flow_push_"+$n).hide();
                                            $n++;
                                        }
                                    }
                                });
                            },
                        });

                        pageObj.getPage(1)
                    }
                }
            });
        },         
        // 标记树结构等级
        getlevel:function(ids){            
            var datajson = "";
            $.ajax({
                type:"POST",
                url: "region/tag/gettopid",
                data:{ids:ids},
                dataType:"json",
                async: false,
                success:function(data){
                    datajson = data;
                }
            });
            return datajson;
        },       
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },                 
        Format:function(fmt){
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份 
                    "d+": this.getDate(), //日 
                    "H+": this.getHours(), //小时 
                    "m+": this.getMinutes(), //分 
                    "s+": this.getSeconds(), //秒 
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
                    "S": this.getMilliseconds() //毫秒 
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter:{
                tag: function (value, row, index) {
                    value = value === null ? '' : value.toString();
                   
                    //渲染Type
                    var html = [];
                    var arr = value.split(',');
                    $.each(arr, function (i, value) {

                        value = value === null ? '' : value.toString();
                        if (value == '')
                            return true;
                        var color = 'primary';
                        var display = value;
                        if(display!=null&&display!=''&&display!='-'){
                            var ind=display.indexOf("_id_");
                            var tag_iff=display.substring(ind+4,display.length);
                            var namea=display.substring(0,ind);
                          html.push('<a title="点击查看详情" class="labelhref" href="#" name="'+namea+'" tag_iff="'+tag_iff+'"><span class="label label-' + color + '" style="font-size:90%;">' + namea + '</span></a>');
                        }else{
                          html.push('<span title="点击查看详情" class="label label-' + color + '" style="font-size:90%;">' + display + '</span>');
                        }
                    });
                    return html.join(' ');
                },
                taglink: function (column, tag, value, row, index, type) {
                    var table = column.table;
                    type = typeof type === 'undefined' ? 'tag' : type;
                    var options = table ? table.bootstrapTable('getOptions') : {};
                    var html = [];
                    var hidden, visible, url, classname, icon, text, title, refresh, confirm, extend;
                    var fieldIndex = column.fieldIndex;

                    $.each(tag, function (i, j) {
                        if (type === 'operate') {
                            if (j.name === 'dragsort' && typeof row[Table.config.dragsortfield] === 'undefined') {
                                return true;
                            }
                            if (['add', 'edit', 'del', 'multi', 'dragsort'].indexOf(j.name) > -1 && !options.extend[j.name + "_url"]) {
                                return true;
                            }
                        }
                        var attr = table.data(type + "-" + j.name);
                        if (typeof attr === 'undefined' || attr) {
                            hidden = typeof j.hidden === 'function' ? j.hidden.call(table, row, j) : (j.hidden ? j.hidden : false);
                            if (hidden) {
                                return true;
                            }
                            visible = typeof j.visible === 'function' ? j.visible.call(table, row, j) : (j.visible ? j.visible : true);
                            if (!visible) {
                                return true;
                            }
                            url = j.url ? j.url : '';
                            url = typeof url === 'function' ? url.call(table, row, j) : (url ? Fast.api.fixurl(Table.api.replaceurl(url, row, table)) : 'javascript:;');
                            classname = j.classname ? j.classname : 'btn-primary btn-' + name + 'one';
                            icon = j.icon ? j.icon : '';
                            text = j.text ? j.text : '';
                            title = j.title ? j.title : text;
                            refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : '';
                            confirm = j.confirm ? 'data-confirm="' + j.confirm + '"' : '';
                            extend = j.extend ? j.extend : '';
                            html.push('<a href="' + url + '" class="' + classname + '" ' + (confirm ? confirm + ' ' : '') + (refresh ? refresh + ' ' : '') + extend + ' title="' + title + '" data-table-id="' + (table ? table.attr("id") : '') + '" data-field-index="' + fieldIndex + '" data-row-index="' + index + '" data-button-index="' + i + '"><i class="' + icon + '"></i>' + (text ? ' ' + text : '') + '</a>');
                        }
                    });
                    return html.join(' ');
                },
            }
        },

        //共用的方法   获取对象的长度
        objLength: function(obj){
            var count = 0;
            for(var i in obj){
                count ++;
            }
            return count;
        },

        piechart: function(json, type, id ,idname){ //画图 饼图/趋势图   数据   类型(画图的字段后期可扩展)  id
          var myChart = echarts.init(document.getElementById(id));
          var lengthdsname = [];
          for(var item of json.series) { // item代表数组里面的元素
            lengthdsname.push(item.name);
          };
          
          var flowname=type;
          if(flowname.length > 40){
            var temp = flowname.substring(0,40)+'...';
          }else{
            temp = flowname;
          }

          $('#'+idname).html(temp);
          $('#'+idname).attr("title", flowname);
          
          var text= temp;
          option = {
            tooltip: {
                trigger: 'axis',
                position:'inside',
                formatter:function(params, ticket, callback){
                    var tipString = params[0].name + "<br />";
                    var indexColor;
                    if(id.indexOf("property") != -1 ){
                        for (var i = 0, length = params.length; i < length; i++) {
                            if(params[i].value==""||params[i].value==null){
                                var item_val_str = 0+" %";
                            }else{
                                var item_val_str = params[i].value.toFixed(2)+" %";
                            }
                            indexColor = params[i].color;
                            tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                            tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                        }
                    }else{
                        for (var i = 0, length = params.length; i < length; i++) {
                            var item_val = params[i].value;
                            if(item_val < 1000){
                                if(item_val==""||item_val==null){
                                    var item_val_str = 0+" bps";
                                }else{
                                    var item_val_str = item_val.toFixed(2)+" bps";
                                }
                               //var item_val_str = item_val.toFixed(2)+" bps";
                            }else if(1000 < item_val && item_val < 1000 * 1000){
                               var item_val_str = (item_val/(1000)).toFixed(2)+"Kbps";
                            }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000)).toFixed(2)+"Mbps";
                            }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                               var item_val_str = (item_val/(1000*1000*1000)).toFixed(2)+"Gbps";
                            }
                            indexColor = params[i].color;
                            tipString += '<span style="display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background:' + indexColor + '"></span>';
                            tipString += '<span style="color:#fff" data-type ="lineTip" data-val=' + params[i].value / 1000 / 1000 + '>' + params[i].seriesName + '：' + item_val_str + '</span><br />';
                        }
                    }
                    return tipString;
                    
                }
            },
            /*title: {
                left: 'center',
                text: text,
            },*/
            legend: {
                x: 'center',
                y:30,
                data:lengthdsname
             },
            toolbox: {
                feature: {
                    myTool1: {
                            show: true,
                            title: '推送到屏幕',
                            icon:'image:///assets/img/copy.png',
                            //icon: 'path://M432.45,595.444c0,2.177-4.661,6.82-11.305,6.82c-6.475,0-11.306-4.567-11.306-6.82s4.852-6.812,11.306-6.812C427.841,588.632,432.452,593.191,432.45,595.444L432.45,595.444z M421.155,589.876c-3.009,0-5.448,2.495-5.448,5.572s2.439,5.572,5.448,5.572c3.01,0,5.449-2.495,5.449-5.572C426.604,592.371,424.165,589.876,421.155,589.876L421.155,589.876z M421.146,591.891c-1.916,0-3.47,1.589-3.47,3.549c0,1.959,1.554,3.548,3.47,3.548s3.469-1.589,3.469-3.548C424.614,593.479,423.062,591.891,421.146,591.891L421.146,591.891zM421.146,591.891',
                            onclick: function (){
                                $.ajax({
                                    url: 'general/screens/index',
                                    type:'post',
                                    //data: {ids:tag_id,names:names,starttime:starttime3,endtime:endtime3,gradename:gradename3},
                                    dataType:'json',
                                    success:function(json){
                                        if(json.total<1){
                                            Toastr.error("请先到屏幕维护-配置屏幕页面，配置屏幕名称");
                                        }else{
                                            var tag_id = $("#ids").html();
                                            var getlevel_val = $("#getlevel").val();
                                            var getlevel = eval('(' + getlevel_val + ')');                
                                            //获取ID
                                            var first_id = getlevel.first_id;
                                            console.log(getlevel.first_id);
                                            Fast.api.open("resources/tag/add_screen/ids/"+tag_id+"?regionid="+first_id+"&from=tag","选择屏幕");
                                        }
                                    }
                                });
                            }
                    },
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data : json.xAxis,
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                }
            },
            yAxis: {
                type: 'value',
                boundaryGap: [0, '100%'],
                splitLine: {
                    show: true,
                    lineStyle: {
                        type: 'dashed'
                    }
                },
                axisLabel: {
                    formatter:function(item_val){
                        if(id.indexOf("property") != -1 ){
                            return Math.floor(item_val) + ' %';
                        }else{
                            if(item_val < 1000){
                               return Math.floor(item_val)+" bps";
                            }else if(1000 < item_val && item_val < 1000 * 1000){
                               return Math.floor(item_val/(1000))+"Kbps";
                            }else if(1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000){
                               return Math.floor(item_val/(1000*1000))+"Mbps";
                            }else if(1000 * 1000 * 1000 <= item_val && item_val < 1000 * 1000 * 1000 * 1000){
                               return Math.floor(item_val/(1000*1000*1000))+"Gbps";
                            }
                        }    
                    },
                },
            },
            /*dataZoom: [{
                show:true,
                //type: 'inside',//鼠标滚动影响图标拖动
                type: 'slider',
                start: 85,
                end: 100,
                zoomOnMouseWheel:false,
            }, {
                start: 0,
                end: 10,
                handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
                handleSize: '80%',
                handleStyle: {
                    color: '#fff',
                    shadowBlur: 3,
                    shadowColor: 'rgba(0, 0, 0, 0.6)',
                    shadowOffsetX: 2,
                    shadowOffsetY: 2
                }
            }],
            grid: [
                    { 
                      left: '7%',
                      right: '10%',
                      width: '91%'
                  }
                   
            ],*/
            series: [
                {
                    name:json.series[0].name,
                    type:'line',
                    smooth:true,
                    symbol: 'none',
                    sampling: 'average',
                    /*itemStyle: {
                        color: 'rgb(255, 70, 131)'
                    },
                    areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: 'rgb(255, 158, 68)'
                        }, {
                            offset: 1,
                            color: 'rgb(255, 70, 131)'
                        }])
                    },*/
                    itemStyle: {
                        normal: {
                            //color: '#00aa00',
                            //color:'linear-gradient(top, white, red)',
                            opacity: 1,
                            barBorderRadius: 5,
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 1,
                                color: '#c8edc8'
                            }, {
                                offset: 0,
                                color: '#00aa00'
                            }])

                        }
                    },
                    areaStyle: {
                        normal: {
                        }
                    },
                    lineStyle: {
                        normal: {
                            color: '#047d04',
                            width: 1.5
                        }
                    },
                    data:json.series[0].data
                }
                // ,{
                //     name:json.series[1].name,
                //     type:'line',
                //     smooth:true,
                //     symbol: 'none',
                //     sampling: 'average',
                //     /*itemStyle: {
                //         color: 'rgb(255, 70, 131)'
                //     },
                //     areaStyle: {
                //         color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                //             offset: 0,
                //             color: 'rgb(255, 158, 68)'
                //         }, {
                //             offset: 1,
                //             color: 'rgb(255, 70, 131)'
                //         }])
                //     },*/
                //     itemStyle: {
                //         normal: {
                //             //color: '#002a97',
                //             //color:'linear-gradient(top, white, red)',
                //             opacity: 1,
                //             barBorderRadius: 5,

                //             color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                //                 offset: 1,
                //                 color: '#9a9aff'
                //             }, {
                //                 offset: 0,
                //                 color: '#002a97'
                //             }])
                //         }
                //     },
                //     areaStyle: {
                //         normal: {
                //         },
                //     },
                //     lineStyle: {
                //         normal: {
                //             color: '#03037b',
                //             width: 1.5
                //         }
                //     },
                //     data:json.series[1].data
                // }
            ]
          };
         //使用刚指定的配置项和数据显示图表
          myChart.clear();
          myChart.setOption(option,true);
          window.addEventListener("resize", function () {
            myChart.resize();
          });
          myChart.dispatchAction({ // 默认启动 toolbox 中 dataZoom 的区域缩放状态
                type: "takeGlobalCursor",
                key: "dataZoomSelect",
                dataZoomSelectActive: true
          });
          setInterval(function () {
                if ($("#"+id).width() != $("#"+id+" canvas").width() && $("#"+id+" canvas").width() < $("#"+id).width()) {
                    myChart.resize();
                }
            }, 700);
          
        },

        //  单个流量图的详情
        singleDetails: function(id,name,type){            
            //  获取当前页面的url
            var url = window.location.host+'/screen/drawing/detail?id='+id+'&name='+name+'&type='+type;        
            window.open('http://'+url);
        },

    };
    return Controller;
});